import Vue from 'vue'
import App from './App'
import store from './store'

// 支持cookie
import 'weapp-cookie';

// 全局基础文件
import config from '@/assets/config/config.js';
import globalFuns from '@/utils/globalFuns.js';
Vue.use(globalFuns);
Vue.use(config);

// 注册全局组件
import Popup from '@/components/Popup/Popup.vue';
import Navbar from '@/components/Navigation/Navbar.vue';
Vue.component('Popup', Popup);
Vue.component('Navbar', Navbar);

// 主题切换
// import theme from '@/utils/theme';
// Vue.use(theme);

Vue.prototype.$store = store
Vue.config.productionTip = false

App.mpType = 'app'

function isPromise(obj) {
  return (
    !!obj &&
    (typeof obj === "object" || typeof obj === "function") &&
    typeof obj.then === "function"
  );
}

uni.addInterceptor({
  returnValue(res) {
    if (!isPromise(res)) {
      return res;
    }
    return new Promise((resolve, reject) => {
      res.then((res) => {
        if (res[0]) {
          reject(res[0]);
        } else {
          resolve(res[1]);
        }
      });
    });
  },
});

const app = new Vue({
  ...App
})
app.$mount()
